#encoding=utf-8
from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression, SGDRegressor, Ridge, LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error, classification_report
import pandas as pd
import numpy as np

def logistic():
    #构造列标签名字
    column = ['Sample code number', 'Clump Thickness','Uniformity of Cell Size','Uniformity of Cell Shape','Marginal Adhesion','Single Epithelial Cell Size','Bare Nuclei','Bland Chromatin','Normal Nucleoli','Mitoses','Class']

    data = pd.read_csv('./data/logic/breast-cancer-wisconsin.data', names=column)

    print(data)

    #缺失值进行处理
    data = data.replace(to_replace='?', value=np.nan)

    data = data.dropna()

    #数据分割 参数1：特征值，2：目标值
    x_train, x_test, y_train, y_test = train_test_split(data[column[1:10]], data[column[10]])

    #标准化
    std = StandardScaler()

    x_train = std.fit_transform(x_train)
    x_test = std.transform(x_test)

    lg = LogisticRegression(C=1.0)

    lg.fit(x_train, y_train)

    print(lg.coef_)
    y_predict = lg.predict(x_test)
    print("准确率：",lg.score(x_test, y_test))
    print("召回率：", classification_report(y_test, y_predict, labels=[2,4],target_names=['良性','恶性']))

    return None

if __name__ == "__main__":
    logistic()